package com.zw.stock_sell_storage.controller;

import com.zw.stock_sell_storage.dto.PurchasingCarDto;
import com.zw.stock_sell_storage.dto.PurchasingInformationDto;
import com.zw.stock_sell_storage.dto.ex.UserDtoEx;
import com.zw.stock_sell_storage.service.IPurchasingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/purchasingCar")
public class PurchasingCarController {
    @Autowired
    IPurchasingCarService iPurchasingCarService;

    @RequestMapping("/queryPurchasingCarList")
    public List<PurchasingCarDto> queryPurchasingCarList(HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        return iPurchasingCarService.queryPurchasingCarList(userDtoEx.getUserId());
    }

    @RequestMapping("/addPurchasingCar")
    public boolean addPurchasingCar(@RequestBody PurchasingCarDto purchasingCarDto,HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        purchasingCarDto.setFkUserId(userDtoEx.getUserId());
        return iPurchasingCarService.addPurchasingCar(purchasingCarDto);
    }

    @RequestMapping("/updatePurchasingCar")
    public boolean updatePurchasingCar(@RequestBody PurchasingCarDto purchasingCarDto){
        return iPurchasingCarService.updatePurchasingCar(purchasingCarDto);
    }

    @RequestMapping("/rmvPurchasingCarById")
    public boolean rmvPurchasingCarById(int purchasingCarId){
        return iPurchasingCarService.rmvPurchasingCarById(purchasingCarId);
    }

    @RequestMapping("/rmvAllPurchasingCar")
    public boolean rmvAllPurchasingCar(int userId){
        return iPurchasingCarService.rmvAllPurchasingCar(userId);
    }

    @RequestMapping("/pushPurchasingCar")
    public boolean pushPurchasingCar(@RequestBody PurchasingInformationDto purchasingInformationDto, HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        return iPurchasingCarService.pushPurchasingCar(purchasingInformationDto,userDtoEx.getUserId());
    }
}
